package com.databasir.core;


import com.databasir.core.meta.data.DatabaseMeta;
import com.databasir.core.meta.provider.MetaProviders;
import com.databasir.core.meta.provider.condition.Condition;
import com.databasir.core.render.RenderConfig;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.io.OutputStream;
import java.sql.Connection;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Getter
public class Databasir {
    private final DatabasirConfig config;

    // pre compile regex
    private Optional<DatabaseMeta> get(Connection connection, String databaseName, String schemaName){
          List<Pattern> ignoreTableNamePatterns = config.getIgnoreTableNameRegex().stream()
                .map(Pattern::compile)
                .collect(Collectors.toList());

          List<Pattern> ignoreTableColumnNamePatterns = config.getIgnoreTableColumnNameRegex()
                .stream()
                .map(Pattern::compile)
                .collect(Collectors.toList());

          Condition condition = Condition.builder()
                .databaseName(databaseName)
                .schemaName(schemaName)
                .ignoreTableNamePatterns(ignoreTableNamePatterns)
                .ignoreTableColumnNamePatterns(ignoreTableColumnNamePatterns)
                  .build();
          return MetaProviders
                  .of(connection)
                  .select(connection,condition);
   }
    public void renderAsMarkdown(DatabaseMeta meta, OutputStream out){



    }

    public void renderAsMarkdown(RenderConfig config,DatabaseMeta meta,OutputStream stream){




    }













}
